package com.yunhe.action;



import java.util.ArrayList;
import java.util.List;

import com.yunhe.biz.IOptionBiz;
import com.yunhe.biz.ISubjectBiz;
import com.yunhe.biz.impl.OptionBizImpl;
import com.yunhe.biz.impl.SubjectBizImpl;
import com.yunhe.entity.Item;
import com.yunhe.entity.Option;
import com.yunhe.entity.Subject;

/**
 * subject操作
 * */
public class SubjectAction {
	//创建subject对象
	private Subject subject;
	//获取subject选项值
	private String[] options;
	//获取选项的id
	private String[] option_id;
	
	public String[] getOption_id() {
		return option_id;
	}
	public void setOption_id(String[] option_id) {
		this.option_id = option_id;
	}
	public Subject getSubject() {
		return subject;
	}
	public void setSubject(Subject subject) {
		this.subject = subject;
	}
	public String[] getOptions() {
		return options;
	}
	public void setOptions(String[] options) {
		this.options = options;
	}
	
	
	private IOptionBiz ob;
	private ISubjectBiz sb;
	
	
	public IOptionBiz getOb() {
		return ob;
	}
	public void setOb(IOptionBiz ob) {
		this.ob = ob;
	}
	public ISubjectBiz getSb() {
		return sb;
	}
	public void setSb(ISubjectBiz sb) {
		this.sb = sb;
	}
	public String save(){
		
		//添加subject
		sb.addSubject(subject);
		//将选项值付给subject
		for(int i=0;i<options.length;i++){
				if(!"".equals(options[i])){
					Option option = new Option();
					option.setVo_option(options[i]);
					option.setSubject(subject);
					ob.addOption(option);
				}
		}
			
		return "save";
	}
	/**
	 * 传入修改页面
	 * */
	public String update(){
	
		//创建subject对象
	
		subject = sb.searchSubject(subject.getVs_id());
		return "update";
	}
	/**
	 * 修改页面
	 * */
	public String sucUpdate(){
		//创建subject对象
		
		//创建option对象
		
		sb.updateSubject(subject);
		//option处理
		for(int i=0;i<options.length;i++){
			if(!"".equals(options[i])){
				if(option_id==null||i>=option_id.length){
					Option option = new Option();
					option.setVo_option(options[i]);
					option.setSubject(subject);
					ob.addOption(option);
				}
				else{
					Integer id = Integer.parseInt(option_id[i]);					
					Option option = ob.searchOption(id);
					option.setSubject(subject);
					option.setVo_option(options[i]);
					ob.updateOption(option);
				}	
			}
		}
		return "sucUpdate";
	}
}
